<template>
     <div class="content-comment">
    <div class="content-comment-title">评论管理</div>
    <div>
      <el-table
        :data="tableData"
        style="width: 100%"
        :default-sort="{ prop: 'date', order: 'descending' }"
      >
          <el-table-column prop="ids" sortable=""  label="id"  width="100">
             <template slot-scope="scope">
                <i class="el-icon-price-tag"></i>
                <span style="margin-left: 10px">{{ scope.row.commId }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="date" label="添加日期" sortable width="180">
             <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.commentTime }}</span>
          </template>
        </el-table-column>
          <el-table-column prop="date" label="修改日期" sortable width="180">
             <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.commentUpdateTime }}</span>
          </template>
        </el-table-column>
          <el-table-column label="用户" width="180">
          <template slot-scope="scope">
            <span>
              <img class="imagesss" :src="scope.row.userInfoArticle.userImg" alt="">
            </span>
            <span  style="margin-left: 10px; overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;">{{ scope.row.userInfoArticle.userName }}</span>
          </template>
        </el-table-column>

         </el-table-column>
          <el-table-column prop="date" label="文章" sortable width="340">
             <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                    <el-tag size="medium">{{ scope.row.articleTitle }}</el-tag>
              </div>
          </template>
        </el-table-column>

         </el-table-column>
          <el-table-column prop="date" label="评论内容" sortable width="220">
             <template slot-scope="scope">
                <span style="margin-left: 10px;  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;" v-html="scope.row.commentContent"></span>
          </template>
        </el-table-column>

         <el-table-column label="是否删除" width="160">
          <template slot-scope="scope">
            <el-tooltip :content="'当前状态: ' + scope.row.isdelete" placement="top">
              <el-switch
                v-model="scope.row.isdelete"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value=0
                :inactive-value=1
                active-text="显示"
                inactive-text="删除"
              >
              </el-switch>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div >

        <div class="limitpage" style="margin-left: 28%;margin-top:30px">
              <el-pagination

          @size-change="handleSizeChange"

          @current-change="handleCurrentChange"

          :current-page="currentPage"

          :page-size="pageSize"

          layout="total, sizes, prev, pager, next, jumper"

          :total="total"

          :pager-count="5"

        >

        </el-pagination>
        </div>
         

       
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "CommentAdmininistration",
  data() {
    return {
      tableData: [], //展示数据
      searchValue: "", //搜索

      currentPage: 1, //当前默认显示第几页

      start: 0, //当前页面从第几条数据开始展示

      pageSize: 10, // 每页显示多少条数据，记住这里一定要是10的倍数，不然无效

      total: 0, //数据总条数
    };
  },

  mounted() {
    this.getClassifitionInfo(this.currentPage, this.pageSize);
  },
  methods: {
    //查询类型信息
    getClassifitionInfo(pageNum, pageSize) {
      const that = this;
      axios({
        method: "post",
        url:
          "/aabbcc/userArticleComment/selectAllcomment/" +
          pageNum +
          "/" +
          pageSize,
      }).then(function (res) {
        console.log(res);
        if (res.data.code == 200) {
          console.log(res.data.obj.comData);
          that.tableData = res.data.obj.comData;
          that.total = res.data.obj.total;
          that.open2(res.data.massage);
        } else {
          that.open4(res.data.massage);
        }
      });
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    //分页  size-change  pageSize 改变时会触发 每页条数

    handleSizeChange(val) {
      this.pageSize = val;
      // this.getA(); //引入你要加载的数据函数
      const loading = this.$loading({
        lock: true,

        text: "加载中",

        spinner: "el-icon-loading",

        background: "rgba(0, 0, 0, 0.7)",
      });
      this.getClassifitionInfo(this.currentPage, val);
      loading.close();
    },

    //current-change  currentPage 改变时会触发  当前页

    async handleCurrentChange(val) {
      //数据较多，加载较慢时可以加一个elementUI的加载框，起到缓冲且项目优化美观作用

      const loading = this.$loading({
        lock: true,

        text: "加载中",

        spinner: "el-icon-loading",

        background: "rgba(0, 0, 0, 0.7)",
      });
      this.getClassifitionInfo(val, this.pageSize);
      loading.close();
    },

    //弹框是否确认
    open() {
      this.$confirm("是否执行操作", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    open4(message) {
      //错误提示框
      this.$message({
        showClose: true,
        message: message,
        type: "error",
      });
    },
    open2(message) {
      //成功提示框
      this.$message({
        showClose: true,
        message: message,
        type: "success",
      });
    },
  },
};
</script>

<style scoped>
.imagesss {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #ccc;
  position: relative;
  top: 5px;
}

.content-comment {
  width: 100%;
  height: 100%;
}
.content-comment-title {
  height: 30px;
  font-size: 18px;
  padding-bottom: 5px;
  border-bottom: 2px solid #ccc;
}
</style>